package main

import (
	"fmt"
	"math/rand"
	"strconv"
)

type RandomQueue struct {
	Min    int
	Max    int
	Length int
	Seed   int64
}

var randomQueue = &RandomQueue{}

func Initialize(min, max, length int, seed int64) {
	randomQueue = &RandomQueue{Min: min, Max: max, Length: length, Seed: seed}
}

func GetRandomQueue() *RandomQueue {
	return randomQueue
}

func (r *RandomQueue) GetData() []int {
	data := make([]int, r.Length)

	// 设置种子
	randClient := rand.New(rand.NewSource(r.Seed))

	// 逐个生成随机数，并确保其不重复
	uniqueMap := make(map[int]struct{})
	for i := 0; i < r.Length; {
		value := randClient.Intn(r.Max-r.Min) + r.Min
		if _, ok := uniqueMap[value]; !ok {
			data[i] = value
			uniqueMap[value] = struct{}{}
			i++
		}
	}
	return data
}

func (r *RandomQueue) Print() {
	data := r.GetData()

	// 获取数字的位数，用于对齐补0
	numLen := len(strconv.Itoa(r.Max))
	fmt.Printf("得到的随机数列为：")
	for _, v := range data {
		fmt.Printf("%0*d ", numLen, v)
	}
}
